﻿package mortal.game.view.guildNew.mercenary
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.mvc.core.*;

    public class GuildNewMercenaryCell extends GCellRenderer
    {
        protected var _nameTxt:GTextFiled;
        protected var _power:GTextFiled;
        protected var _job:GTextFiled;
        protected var _levelTxt:GTextFiled;
        protected var _unit:GTextFiled;
        protected var _times:GTextFiled;
        protected var _overTime:GTextFiled;
        protected var _mercenBtn:GButton;
        protected var _line:ScaleBitmap;
        protected var _coinBm:GBitmap;
        private var _bgSelected:ScaleBitmap;
        private var _isSelected:Boolean = false;
        private var _info:SGuildMercenary;
        private var _btnF:Boolean = false;

        public function GuildNewMercenaryCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._nameTxt = UIFactory.gTextField("", 10, 4, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._power = UIFactory.gTextField("100", 114, 4, 70, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._job = UIFactory.gTextField("", 208, 4, 60, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._levelTxt = UIFactory.gTextField("Lv.100", 291, 4, 50, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._unit = UIFactory.gTextField("100", 339, 4, 80, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).right());
            this._times = UIFactory.gTextField("0/5", 472, 4, 50, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._overTime = UIFactory.gTextField("", 553, 4, 90, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._mercenBtn = UIFactory.gButton("" + Language.getString(71533), 658, 3, 66, 23, this);
            this._line = UIFactory.bg(5, 30, 755, 1, this, ImagesConst.SplitLine);
            this._coinBm = UIFactory.gBitmap(ImagesConst.Jinbi, 421, 5, this);
            this._bgSelected = UIFactory.bg(0, 0, 745, 30, this, "selectFilter");
            this._mercenBtn.configEventListener(MouseEvent.CLICK, this.onMercenaryHd);
            this.setBtn(false);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._nameTxt = null;
            this._power = null;
            this._job = null;
            this._levelTxt = null;
            this._unit = null;
            this._times = null;
            this._overTime = null;
            this._mercenBtn = null;
            this._line = null;
            this._coinBm = null;
            this._bgSelected = null;
            super.disposeImpl(param1);
            return;
        }// end function

        override public function set selected(param1:Boolean) : void
        {
            this._isSelected = param1;
            if (this._isSelected)
            {
                this._bgSelected.visible = true;
            }
            else
            {
                this._bgSelected.visible = false;
            }
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            this._info = param1 as SGuildMercenary;
            if (this._info == null)
            {
                return;
            }
            this._nameTxt.text = this._info.name;
            this._power.text = "" + this._info.combat;
            this._job.text = GameDefConfig.instance.getItem("ECareer", this._info.career).text;
            this._levelTxt.text = "Lv." + this._info.level;
            this._unit.text = "" + this._info.money;
            this._times.text = "" + this._info.count + "/" + GuildNewMercenaryProcessor.oneDayTimes + Language.getString(71534);
            this.updateDate();
            this.updateBtn();
            return;
        }// end function

        private function updateDate() : void
        {
            var _loc_4:int = 0;
            var _loc_1:* = ClockManager.instance.nowDate;
            var _loc_2:* = (this._info.creatdt.time - _loc_1.time) / 1000;
            this._btnF = true;
            var _loc_3:* = _loc_2 / 3600;
            if (_loc_2 > 0)
            {
                this._overTime.textColor = 16777215;
                _loc_3 = _loc_2 / 3600;
                _loc_4 = _loc_2 / 60 % 60;
            }
            else
            {
                this._btnF = false;
                _loc_3 = 0;
                _loc_4 = 0;
                this._overTime.textColor = 16711680;
            }
            this._overTime.text = Language.getStringByParam(71535, _loc_3, _loc_4);
            return;
        }// end function

        private function updateBtn() : void
        {
            if (!this._btnF || this.canNotRent())
            {
                this.setBtn(false);
                return;
            }
            if (this._info.count >= GuildNewMercenaryProcessor.oneDayTimes || this._info.myCount >= GuildNewMercenaryProcessor.onePersonTimes || Cache.instance.role.entityInfo.entityId.id == this._info.playerId)
            {
                this.setBtn(false);
                return;
            }
            this.setBtn(true);
            return;
        }// end function

        private function canNotRent() : Boolean
        {
            var _loc_1:* = GuildNewMercenaryProcessor.canRentCopy;
            return !_loc_1;
        }// end function

        private function setBtn(param1:Boolean) : void
        {
            if (param1)
            {
                this._mercenBtn.enabled = true;
                this._mercenBtn.filters = null;
            }
            else
            {
                this._mercenBtn.enabled = false;
                this._mercenBtn.filters = [FilterConst.colorFilter2];
            }
            this._mercenBtn.drawNow();
            return;
        }// end function

        private function onMercenaryHd(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(GuildNewLocalEvent.GuildNewMercenaryGetOne, this._info));
            return;
        }// end function

    }
}
